import request from '@/utils/request'

export function getList(params) {
  return request({
    url: `/device`,
    method: 'get',
    params,
  })
}

export function getOne(serialno, params) {
  return request({
    url: `/device/${serialno}`,
    method: 'get',
    params,
  })
}

export function doAdd(data) {
  return request({
    url: `/device`,
    method: 'post',
    data,
  })
}

export function doEdit(serialno, data) {
  return request({
    url: `/device/${serialno}`,
    method: 'patch',
    data,
  })
}

export function doDelete(serialno) {
  return request({
    url: `/device/${serialno}`,
    method: 'delete',
  })
}

export function doMultiDelete(serialnos) {
  return request({
    url: `/device/multserialnoelete`,
    method: 'delete',
    data: { serialnos },
  })
}

export function doCommand(serialno, data) {
  return request({
    url: `/device/${serialno}/command`,
    method: 'post',
    data,
  })
}

export function doStates(serialno, params) {
  return request({
    url: `/device/${serialno}/states`,
    method: 'get',
    params,
  })
}

export function doUsual(data) {
  return request({
    url: `/device/usual`,
    method: 'post',
    data,
  })
}

export function selectForCloud(params) {
  return request({
    url: `/remote/index`,
    method: 'get',
    params,
  })
}

export function sendCommand(data, serialno) {
  return request({
    url: `/remote/${serialno}/sendCommand`,
    method: 'post',
    data,
  })
}

export function sendPWM(serialno, data) {
  return request({
    url: `/remote/${serialno}/sendPWM`,
    method: 'post',
    data,
  })
}

export function getActionDays(serialno, params) {
  return request({
    url: `/remote/${serialno}/getActionDays`,
    method: 'get',
    params,
  })
}

export function getActions(params) {
  return request({
    url: `/remote/getActions`,
    method: 'get',
    params,
  })
}

export function census(params) {
  return request({
    url: `/remote/census`,
    method: 'get',
    params,
  })
}

export function statistics(params) {
  return request({
    url: `/remote/statistics`,
    method: 'get',
    params,
  })
}

export function weather(id, params) {
  return request({
    url: `/remote/weather/${id}`,
    method: 'get',
    params,
  })
}

export function weatherDaily(params) {
  return request({
    url: `/remote/weatherDaily`,
    method: 'get',
    params,
  })
}

export function plans(serialno, params) {
  return request({
    url: `/remote/plans/${serialno}`,
    method: 'get',
    params,
  })
}

export function cancelPlan(id) {
  return request({
    url: `/remote/cancelPlan/${id}`,
    method: 'put',
  })
}

export function delPlan(id) {
  return request({
    url: `/remote/delPlan/${id}`,
    method: 'put',
  })
}

export function addPlan(data) {
  return request({
    url: `/remote/addPlan`,
    method: 'post',
    data,
  })
}

export function getGridType(id) {
  return request({
    url: `/remote/gridType/${id}`,
    method: 'get',
  })
}

export function updateGridType(id, data) {
  return request({
    url: `/remote/gridType/${id}`,
    method: 'patch',
    data,
  })
}

export function getGridPartitions(params) {
  return request({
    url: `/remote/gridPartition`,
    method: 'get',
    params,
  })
}

export function deleteGridPartition(id) {
  return request({
    url: `/remote/gridPartition`,
    method: 'delete',
    params: { id },
  })
}

export function getGrids(params) {
  return request({
    url: `/remote/grid`,
    method: 'get',
    params,
  })
}

export function addGrid(data) {
  return request({
    url: `/remote/grid`,
    method: 'post',
    data,
  })
}

export function activeGrid(id) {
  return request({
    url: `/remote/grid/${id}/default`,
    method: 'post',
  })
}

export function deleteGrid(id) {
  return request({
    url: `/remote/grid`,
    method: 'delete',
    params: { id },
  })
}

export function getSoils(params) {
  return request({
    url: `/remote/soil`,
    method: 'get',
    params,
  })
}

export function updateSoil(id, data) {
  return request({
    url: `/remote/soil/${id}`,
    method: 'patch',
    data,
  })
}

export function getCrops(params) {
  return request({
    url: `/remote/crop`,
    method: 'get',
    params,
  })
}

export function updateCrop(id, data) {
  return request({
    url: `/remote/crop/${id}`,
    method: 'patch',
    data,
  })
}

export function updateDevice(serailno, data) {
  return request({
    url: `/remote/device/${serailno}`,
    method: 'put',
    data,
  })
}

export function getCell(serialno) {
  return request({
    url: `/remote/${serialno}/cell`,
    method: 'get',
  })
}

export function setCell(serialno, data) {
  return request({
    url: `/remote/${serialno}/cell`,
    method: 'post',
    data,
  })
}
